﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using matrixdotnet.Common;

namespace matrixdotnet.CommonDALImp
{
    public abstract class MappedDataEntity<TIdentity, TUniqueKey, TBusinessEntity, TDataEntity> :
        DataEntity<TIdentity, TUniqueKey, TBusinessEntity>
        where TIdentity : struct
        where TUniqueKey : struct
        where TBusinessEntity : class, IBusinessEntity<TUniqueKey>
        // where TDataEntity : class, IDataEntity<TIdentity, TUniqueKey, TBusinessEntity>, TBusinessEntity
        where TDataEntity : MappedDataEntity<TIdentity, TUniqueKey, TBusinessEntity, TDataEntity>, TBusinessEntity
    {
        protected IFromDataEntityObjectMapper<
            TIdentity,
            TUniqueKey,
            TBusinessEntity,
            TDataEntity> Mapper { get; set; }

        public MappedDataEntity(
            TIdentity identity, TBusinessEntity businessEntity, long version) :
            base(identity, businessEntity, version)
        {
            // Mapper = mapper;
        }

        public MappedDataEntity(TBusinessEntity businessEntity) : base(businessEntity)
        {

        }

        protected override int UpdateEntity()
        {
            return Mapper.Update(TDataEntityCast);
        }

        protected override TIdentity InsertEntity()
        {
            return Mapper.Insert(TDataEntityCast);
        }

        protected override int DeleteEntity()
        {
            return Mapper.Delete(TDataEntityCast);
        }

        protected abstract TDataEntity TDataEntityCast { get; }
    }
}
